<?php

namespace App\Models\Home;

use Illuminate\Database\Eloquent\Model;

class Config extends Model
{
    protected $table = 'config';
    protected $guarded = [];
    public $timestamps = false;

    public function getConfig($config_name = array()){

        $res = self::orWhere(function ($query) use($config_name){

            if (!empty($config_name)){

                foreach ($config_name as $name){

                    $query->orWhere('name', $name);

                }
            }

        })->get();

        $config = [];

        foreach ($res as $k => $v){

            $config[$v->name] = $v->val;

        }

        return $config;

    }
    public function getConf($config_name = null)
    {
        if ($config_name){

            $res = self::Where('name', $config_name)->first();

            if ($res){

                return $res->val;

            }else{

                return '';

            }

        }else{

            return '';

        }

    }

}
